Finding first space character using contains

OK, here is yet another, probably, stupid question...  I am reading in a file line by line and looking for the first space character but keep getting a value of -1 when using the contains function.  Here is the code I've been trying to use:

void readFileIntoAttributes(Stream file) {
    string sLine, attr, val;
    Buffer bufLine = create;
    int nSpace, nLineNum = 0;
    
    Module m = currMod;
    
    while (!end file) {
        file >= bufLine;      //Read a single line into bufLine buffer
        attr = "*Contract Number";
        nSpace = contains(bufLine, " ", 10);  //Search for first space after "*Contract "
        infoBox("Space at character " nSpace "");
    }
}

I'm assuming it has something to do with the space being a special character.  Do I need to use a backslash?

 

Chris


chrscote - Wed Oct 10 12:20:19 EDT 2018

Re: Finding first space character using contains
O.Wilkop - Thu Oct 11 02:09:55 EDT 2018

Try

nSpace = contains(bufLine, ' ', 10);

instead.

You are using " ", which means you are looking for a word in the buffer. The reference manual notes to this: "returns the index at which string word appears in the buffer, starting from 0, provided the string is preceded by a non-alphanumeric character." So in your case I would assume it would find the space only if there were two spaces in a row. If you use ' ' instead you are looking for a single character space and the limitation of "needs to be preceded by a non-alphanumeric character" doesn't apply.

Re: Finding first space character using contains
chrscote - Thu Oct 11 07:58:52 EDT 2018

O.Wilkop - Thu Oct 11 02:09:55 EDT 2018

Try

nSpace = contains(bufLine, ' ', 10);

instead.

You are using " ", which means you are looking for a word in the buffer. The reference manual notes to this: "returns the index at which string word appears in the buffer, starting from 0, provided the string is preceded by a non-alphanumeric character." So in your case I would assume it would find the space only if there were two spaces in a row. If you use ' ' instead you are looking for a single character space and the limitation of "needs to be preceded by a non-alphanumeric character" doesn't apply.

That is exactly what I needed to fix my issue.  I figured it had to be something simple like that.  Thank you.

 

Chris